/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * edicionDatosCliente.java
 *
 * Created on 14-12-2010, 02:04:38 AM
 */
package vista;

import conexionBaseDatos.InsertInputData;
import javax.swing.JOptionPane;
import validaciones.validacionRutBD;

/**
 *
 * @author David Vallejos A
 */
public class edicionDatosCliente extends javax.swing.JFrame {

    VentanaPrincipal nuevaEdicion = new VentanaPrincipal();
    private String rutTrabajo = "";

    /** Creates new form edicionDatosCliente */
    public edicionDatosCliente() {
        initComponents();

    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel14 = new javax.swing.JPanel();
        jLabel26 = new javax.swing.JLabel();
        jLabel44 = new javax.swing.JLabel();
        jLabel55 = new javax.swing.JLabel();
        jLabel56 = new javax.swing.JLabel();
        jLabel45 = new javax.swing.JLabel();
        jLabel47 = new javax.swing.JLabel();
        jLabel57 = new javax.swing.JLabel();
        aceptarEdicionDatosCliente = new javax.swing.JButton();
        cancelarEdicionDatosCliente = new javax.swing.JButton();
        jSeparator1 = new javax.swing.JSeparator();
        jSeparator2 = new javax.swing.JSeparator();
        CajaNombrePropEdicionDatos = new javax.swing.JTextField();
        cajaApPaternoPropMascEdicionDatos = new javax.swing.JTextField();
        cajaApMaternoPropMascEdicionDatos = new javax.swing.JTextField();
        cajaRutClienteEditable = new javax.swing.JTextField();
        cajaDireccionPropMascEdicionDatos = new javax.swing.JTextField();
        cajaTelefonoPropMascEdicionDatos = new javax.swing.JTextField();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Edicion Datos Cliente");

        jPanel14.setBackground(new java.awt.Color(255, 255, 255));

        jLabel26.setFont(new java.awt.Font("Tahoma", 1, 14));
        jLabel26.setText("Datos Propietario");

        jLabel44.setText("Nombre:");

        jLabel55.setText("Ap. Paterno:");

        jLabel56.setText("Ap. Materno:");

        jLabel45.setText("Rut:");

        jLabel47.setText("Dirección:");

        jLabel57.setText("Teléfono:");

        aceptarEdicionDatosCliente.setText("aceptar");
        aceptarEdicionDatosCliente.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                aceptarEdicionDatosClienteActionPerformed(evt);
            }
        });

        cancelarEdicionDatosCliente.setText("volver");
        cancelarEdicionDatosCliente.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cancelarEdicionDatosClienteActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel14Layout = new javax.swing.GroupLayout(jPanel14);
        jPanel14.setLayout(jPanel14Layout);
        jPanel14Layout.setHorizontalGroup(
            jPanel14Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel14Layout.createSequentialGroup()
                .addGap(18, 18, 18)
                .addGroup(jPanel14Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel14Layout.createSequentialGroup()
                        .addGroup(jPanel14Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel55)
                            .addComponent(jLabel44)
                            .addComponent(jLabel56)
                            .addComponent(jLabel45))
                        .addGroup(jPanel14Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel14Layout.createSequentialGroup()
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addGroup(jPanel14Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel26)
                                    .addGroup(jPanel14Layout.createSequentialGroup()
                                        .addComponent(aceptarEdicionDatosCliente)
                                        .addGap(18, 18, 18)
                                        .addComponent(cancelarEdicionDatosCliente))))
                            .addGroup(jPanel14Layout.createSequentialGroup()
                                .addGap(18, 18, 18)
                                .addGroup(jPanel14Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(cajaApMaternoPropMascEdicionDatos, javax.swing.GroupLayout.DEFAULT_SIZE, 165, Short.MAX_VALUE)
                                    .addComponent(cajaApPaternoPropMascEdicionDatos, javax.swing.GroupLayout.DEFAULT_SIZE, 165, Short.MAX_VALUE)
                                    .addComponent(cajaRutClienteEditable, javax.swing.GroupLayout.DEFAULT_SIZE, 165, Short.MAX_VALUE)
                                    .addComponent(cajaDireccionPropMascEdicionDatos, javax.swing.GroupLayout.DEFAULT_SIZE, 165, Short.MAX_VALUE)
                                    .addComponent(cajaTelefonoPropMascEdicionDatos, javax.swing.GroupLayout.DEFAULT_SIZE, 165, Short.MAX_VALUE)))
                            .addGroup(jPanel14Layout.createSequentialGroup()
                                .addGap(17, 17, 17)
                                .addComponent(CajaNombrePropEdicionDatos, javax.swing.GroupLayout.DEFAULT_SIZE, 166, Short.MAX_VALUE))))
                    .addGroup(jPanel14Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                        .addComponent(jLabel57)
                        .addComponent(jLabel47)))
                .addContainerGap())
            .addComponent(jSeparator1, javax.swing.GroupLayout.DEFAULT_SIZE, 275, Short.MAX_VALUE)
            .addComponent(jSeparator2, javax.swing.GroupLayout.DEFAULT_SIZE, 275, Short.MAX_VALUE)
        );
        jPanel14Layout.setVerticalGroup(
            jPanel14Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel14Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel26)
                .addGap(11, 11, 11)
                .addComponent(jSeparator2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(32, 32, 32)
                .addGroup(jPanel14Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel44)
                    .addComponent(CajaNombrePropEdicionDatos, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPanel14Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel55)
                    .addComponent(cajaApPaternoPropMascEdicionDatos, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPanel14Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel56)
                    .addComponent(cajaApMaternoPropMascEdicionDatos, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPanel14Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel45)
                    .addComponent(cajaRutClienteEditable, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPanel14Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel47)
                    .addComponent(cajaDireccionPropMascEdicionDatos, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPanel14Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel57)
                    .addComponent(cajaTelefonoPropMascEdicionDatos, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 31, Short.MAX_VALUE)
                .addGroup(jPanel14Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(aceptarEdicionDatosCliente)
                    .addComponent(cancelarEdicionDatosCliente))
                .addContainerGap())
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel14, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel14, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void aceptarEdicionDatosClienteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_aceptarEdicionDatosClienteActionPerformed


        this.editarCliente();
        // TODO add your handling code here:
    }//GEN-LAST:event_aceptarEdicionDatosClienteActionPerformed

    private void cancelarEdicionDatosClienteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelarEdicionDatosClienteActionPerformed

        VentanaPrincipal volver = new VentanaPrincipal();
        this.dispose();

        // TODO add your handling code here:
    }//GEN-LAST:event_cancelarEdicionDatosClienteActionPerformed
    /**
     * @param args the command line arguments
     */
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JTextField CajaNombrePropEdicionDatos;
    private javax.swing.JButton aceptarEdicionDatosCliente;
    private javax.swing.JTextField cajaApMaternoPropMascEdicionDatos;
    private javax.swing.JTextField cajaApPaternoPropMascEdicionDatos;
    private javax.swing.JTextField cajaDireccionPropMascEdicionDatos;
    private javax.swing.JTextField cajaRutClienteEditable;
    private javax.swing.JTextField cajaTelefonoPropMascEdicionDatos;
    private javax.swing.JButton cancelarEdicionDatosCliente;
    private javax.swing.JLabel jLabel26;
    private javax.swing.JLabel jLabel44;
    private javax.swing.JLabel jLabel45;
    private javax.swing.JLabel jLabel47;
    private javax.swing.JLabel jLabel55;
    private javax.swing.JLabel jLabel56;
    private javax.swing.JLabel jLabel57;
    private javax.swing.JPanel jPanel14;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JSeparator jSeparator2;
    // End of variables declaration//GEN-END:variables

    public void obtieneRut(String rut) {
        this.rutTrabajo = rut;
    }

    public String getRut() {
        return rutTrabajo;
    }

    public void editarCliente() {

        String rutBD = getRut();
        String nuevoNombre = CajaNombrePropEdicionDatos.getText().toUpperCase();
        String nuevoApPaterno = cajaApPaternoPropMascEdicionDatos.getText().toUpperCase();
        String nuevoApMaterno = cajaApMaternoPropMascEdicionDatos.getText().toUpperCase();
        String nuevoRut = cajaRutClienteEditable.getText().toUpperCase();

        validacionRutBD validaRut = new validacionRutBD();
        validaRut.valida(nuevoRut);

        StringBuilder finale = validaRut.getRutPropietarioMasc();
        String RutNuevoRegistro = finale.toString();

        String nuevaDireccion = cajaDireccionPropMascEdicionDatos.getText().toUpperCase();
        String nuevoTelefono = cajaTelefonoPropMascEdicionDatos.getText().toUpperCase();

        InsertInputData.actualizarDatosCliente(rutBD, RutNuevoRegistro, nuevoNombre, nuevoApPaterno, nuevoApMaterno, nuevaDireccion, nuevoTelefono);

        JOptionPane.showMessageDialog(null, "DATOS INGRESADOS CORRECTAMENTE");

        VentanaPrincipal volver = new VentanaPrincipal();
        this.dispose();

    }
}
